package com.recruit.wechat.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.recruit.wechat.bean.WechatArea;
import com.recruit.wechat.bean.WechatUser;
import com.recruit.wechat.controller.helper.$;
import com.recruit.wechat.controller.model.ApiResultModel;
import com.recruit.wechat.service.WechatUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import com.recruit.wechat.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import com.recruit.wechat.bean.WechatCompany;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LF
 * @since 2020-08-24
 */
@Controller
@RequestMapping("/WeChatUser/wechatCompany")
public class WechatCompanyController extends BaseController{
     /** 主页面 */
    @RequestMapping("admin/main.html")
    public String main(){
       return  "WechatCompany/WechatcompanyMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "admin/addWechatCompanyHtml")
    public String addWechatCompanyHtml(Model model ){
        List<WechatUser> list = wechatUserService.getUserListByTrIsDeleteAndTrIsCompany();
        model.addAttribute("userlist",list);
        return "WechatCompany/WechatcompanyAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/editWechatCompanyHtml")
    public String editWechatCompanyHtml(Integer id ,Model model ){
           model.addAttribute("wechatCompany",wechatCompanyService.selectWechatCompanyByIdWechatCompany(id));
           List<WechatUser> list = wechatUserService.getUserListByTrIsDeleteAndTrIsCompany();
           model.addAttribute("userlist",list);
             return "WechatCompany/WechatcompanyEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/showWechatCompanyHtml")
    public String showWechatCompanyHtml(Integer id ,Model model ){
           model.addAttribute("wechatCompany",wechatCompanyService.selectWechatCompanyByIdWechatCompany(id));
            List<WechatUser> list = wechatUserService.getUserListByTrIsDeleteAndTrIsCompany();
            model.addAttribute("userlist",list);
             return "WechatCompany/WechatcompanyShow";
    }


    /** 分页查询WechatCompany
     * @param page  页码
     * @param limit  查几条
     * @param wechatCompany  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "admin/findWechatCompanyByPage")
    @ResponseBody
    public ResultPage findWechatCompanyByPage(Integer page, Integer limit,WechatCompany wechatCompany){
             return wechatCompanyService.findWechatCompanyByPage(page,limit,wechatCompany);
    }

    /** 添加WechatCompany
     * @param wechatCompany  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/addWechatCompany")
    @ResponseBody
    public ApiResultModel saveWechatCompany(WechatCompany wechatCompany  ){
             return wechatCompanyService.addWechatCompany(wechatCompany);
    }

    /** 编辑WechatCompany
     * @param wechatCompany  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/editWechatCompany")
    @ResponseBody
    public ApiResultModel editWechatCompany(WechatCompany wechatCompany  ){
             return wechatCompanyService.editWechatCompany(wechatCompany);
    }



    /** 删除一条WechatCompany
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/delWechatCompany")
    @ResponseBody
    public ApiResultModel delWechatCompany( Integer id  ){
             return wechatCompanyService.delWechatCompany(id);
    }


    /** 初始化省份
     * @param wechatArea
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/getProvince")
    @ResponseBody
    public ApiResultModel delWechatLabel(WechatArea wechatArea){
        List<WechatArea> wechatAreas = wechatAreaService.selectProvince(wechatArea);
        return $.success(200,"ok",wechatAreas);
    }

    /**
     * 获取所有公司的信息
     */
    @RequestMapping(value = "admin/getCompanyAll")
    @ResponseBody
    public ApiResultModel getCompanyAll(){


        List<WechatCompany> list = wechatCompanyService.list();
        return $.success(200,"ok",list);
    }



}
